package com.db.dao;

import java.sql.Connection;
import java.sql.SQLException;

import javax.sql.DataSource;

import org.apache.commons.dbutils.QueryRunner;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;



public class McmDao extends BaseDAO{
	
	// 单例模式 start
		private volatile static McmDao instance = null;
		
		
		private McmDao() throws SQLException {
			super();

		}
		public static McmDao getInstance() throws SQLException {
			if (instance == null) {
				synchronized (McmDao.class) {// 1
					if (instance == null) {// 2
						instance = new McmDao();// 3
					}
				}
			}
			return instance;
		}
		// 单例模式 end
	



	//qr dataSource connection 实例化
	@Override
	void init() throws SQLException {
		// TODO Auto-generated method stub  db_two
		
		Resource resource = new ClassPathResource("database.xml"); 
		BeanFactory factory = new XmlBeanFactory(resource); 
		
		this.setQr(new QueryRunner());
		this.setDataSource((DataSource)factory.getBean("db_two"));
		this.setConnection(this.getDataSource().getConnection());
		
	}
	
	public static void main(String[] args){
		
	}

}
